{
  "name": "Case 46: Sales Commission Dispute Resolver - Production",
  "nodes": [
    {
      "parameters": {
        "pollTimes": { "item": [{ "mode": "everyMinute" }] },
        "folderToWatch": { "__rl": true, "value": "1KVYvmrXNW48iR_qTA438K4IsF4TbRb8y", "mode": "list" },
        "event": "fileCreated"
      },
      "id": "trigger_case_46",
      "name": "Contract Upload Trigger",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [-1100, 0]
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": { "__rl": true, "value": "={{ $json.id }}", "mode": "id" }
      },
      "id": "download_case_46",
      "name": "Download Contract",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [-900, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj" }] },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": { "parameters": [{ "parameterType": "formBinaryData", "name": "file", "inputDataFieldName": "data" }] }
      },
      "id": "post_case_46",
      "name": "LlamaIndex Upload",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [-700, 0]
    },
    {
      "parameters": { "amount": 20 },
      "id": "wait_case_46",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [-500, 0]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"LlamaIndex Upload\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj" }] }
      },
      "id": "check_case_46",
      "name": "Check Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [-300, 0]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            { "conditions": { "conditions": [{ "leftValue": "={{ $json.status }}", "rightValue": "SUCCESS", "operator": { "type": "string", "operation": "equals" } }] }, "renameOutput": true, "outputKey": "SUCCESS" },
            { "conditions": { "conditions": [{ "leftValue": "={{ $json.status }}", "rightValue": "PENDING", "operator": { "type": "string", "operation": "equals" } }] }, "renameOutput": true, "outputKey": "PENDING" }
          ]
        }
      },
      "id": "switch_case_46",
      "name": "Status Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [-100, 0]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"LlamaIndex Upload\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": { "parameters": [{ "name": "Authorization", "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj" }] }
      },
      "id": "markdown_case_46",
      "name": "Get Markdown",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [150, -100]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            { "name": "Contract ID", "description": "Unique ID of the contract/MSSA." },
            { "name": "Sales Executive", "description": "Name of the agent." },
            { "name": "Total Deal Value", "description": "TCV or Gross Contract Value as a number." },
            { "name": "Agreed Comm %", "description": "The percentage rate (e.g. 5%)." },
            { "name": "Expected Comm", "description": "Calculate: Total Deal Value * (Comm % / 100)." },
            { "name": "Actual Payout", "description": "The amount recorded in payroll disbursement as a number." },
            { "name": "Dispute Amount", "description": "Calculate: Expected Comm - Actual Payout." },
            { "name": "Resolution Status", "description": "If Dispute Amount > 0 return 'Underpaid', else 'Resolved'." },
            { "name": "Risk Level", "description": "If Dispute Amount > 10000 return 'High', else 'Low'." }
          ]
        }
      },
      "id": "extractor_case_46",
      "name": "Commission Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [400, -100]
    },
    {
      "parameters": {
        "jsCode": "return $node[\"Commission Extractor\"].json.output;"
      },
      "id": "flatten_case_46",
      "name": "Flatten Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [600, -100]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "value": "YOUR_SHEET_ID_HERE", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Case_46_Commission_Dispute_Log", "mode": "list" },
        "columns": { "mappingMode": "autoMapInputData" }
      },
      "id": "sheet_case_46",
      "name": "Log Dispute Data",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [850, -100]
    },
    {
      "parameters": {
        "model": { "__rl": true, "value": "gpt-4o-mini", "mode": "list" }
      },
      "id": "llm_case_46",
      "name": "GPT-4o",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [400, 100]
    }
  ],
  "connections": {
    "Contract Upload Trigger": { "main": [[{ "node": "Download Contract", "type": "main", "index": 0 }]] },
    "Download Contract": { "main": [[{ "node": "LlamaIndex Upload", "type": "main", "index": 0 }]] },
    "LlamaIndex Upload": { "main": [[{ "node": "Wait for Parsing", "type": "main", "index": 0 }]] },
    "Wait for Parsing": { "main": [[{ "node": "Check Status", "type": "main", "index": 0 }]] },
    "Check Status": { "main": [[{ "node": "Status Switch", "type": "main", "index": 0 }]] },
    "Status Switch": { "main": [[{ "node": "Get Markdown", "type": "main", "index": 0 }], [{ "node": "Wait for Parsing", "type": "main", "index": 0 }]] },
    "Get Markdown": { "main": [[{ "node": "extractor_case_46", "type": "main", "index": 0 }]] },
    "extractor_case_46": { "main": [[{ "node": "flatten_case_46", "type": "main", "index": 0 }]] },
    "flatten_case_46": { "main": [[{ "node": "sheet_case_46", "type": "main", "index": 0 }]] },
    "GPT-4o": { "ai_languageModel": [[{ "node": "extractor_case_46", "type": "ai_languageModel", "index": 0 }]] }
  }
}